#include <ros/ros.h>
#include <tf/transform_listener.h>
#include <geometry_msgs/PoseStamped.h>

int main(int argc, char** argv)
{
	//初始化ROS节点信息
	ros::init(argc, argv, "tf_listener");
	ros::NodeHandle n;
	
	//创建TF监听器
	tf::TransformListener listener;
	
	ros::Rate rate(10.0);
	while(ros::ok())
	{
		//在base_laser上声明一个点laser_point，用来转换得到base_link上的点坐标
		geometry_msgs::PointStamped laser_point;
		laser_point.header.frame_id = "base_laser";
		//使用最近可用的转换
		laser_point.header.stamp = ros::Time();
		
		//laser_point检测点获取
		laser_point.point.x = 0.3;
		laser_point.point.y = 0.0;
		laser_point.point.z = 0.0;
		
		try
		{
			//监听获取tf变换
			listener.waitForTransform("base_link", "base_laser", ros::Time(0), ros::Duration(3.0));
			
			geometry_msgs::PointStamped base_point;
			base_point.header.frame_id = "base_link";
			listener.transformPoint("base_link", laser_point, base_point);
			
			//将坐标变换值进行打印
			ROS_INFO("Change laser_point:(%.2f, %.2f, %.2f) to base_point(%.2f, %.2f, %.2f) at Time %.2f", laser_point.point.x, laser_point.point.y, laser_point.point.z, base_point.point.x, base_point.point.y, base_point.point.z, base_point.header.stamp.toSec());
		}
		catch(tf::TransformException& ex)
		{
			ROS_ERROR("%s", ex.what());
			ros::Duration(1.0).sleep();
			continue;
		}
		rate.sleep();
	}
	return 0;
}
